import Vue from 'vue'
import Vuex from 'vuex'
import { getItem, setItem } from '@/utils/storage'

Vue.use(Vuex)
export const TOKEN_KEY = 'userToken'

export default new Vuex.Store({
  state: {
    token: getItem(TOKEN_KEY),
    userInfo: null,
    articleId: ''
  },
  getters: {
  },
  mutations: {
    //更新token值
    updateToken(state, payload) {
      console.log(payload);
      state.token = payload
      //存储数据
      setItem(TOKEN_KEY, state.token)
    },
    //更新用户信息
    updateUserInfo(state, payload) {
      state.userInfo = payload
    },
    //更新文章ID值
    updateArticleId(state, payload) {
      state.articleId = payload
    }
  },
  actions: {
  },
  modules: {
  }
})
